#include "gtest/gtest.h"
#include "TDBase.h"

TEST (MapExplorer, Init)
{
	StageMap map;

	//	+--+--+--+--+
	//	| 0| 1| 2| 3|
	//	+--+--+--+--+  +--+
	//	| 4|  | 5| 6|  | 7|
	//	+--+  +--+--+  +--+

	map.Append(MapBrick(0,vector3di( 0,0,4),0,false,true,-1, 1, 4,-1));
	map.Append(MapBrick(0,vector3di( 2,0,4),0,false,true,-1, 2,-1, 0));
	map.Append(MapBrick(0,vector3di( 4,0,4),0,false,true,-1, 3, 5, 1));
	map.Append(MapBrick(0,vector3di( 6,0,4),0,false,true,-1,-1, 6, 2));
	map.Append(MapBrick(0,vector3di( 0,0,2),0,false,true, 0,-1,-1,-1));
	map.Append(MapBrick(0,vector3di( 4,0,2),0,false,true, 2, 6,-1,-1));
	map.Append(MapBrick(0,vector3di( 6,0,2),0,false,true,-1,-1, 5, 3));
	map.Append(MapBrick(0,vector3di(10,0,2),0,false,true,-1,-1,-1,-1));

	dynamic_bitset explorer(map.Size());
	PathFinder finder;
	finder.Explore(map, 0, 6, explorer);

	for (int i=0; i<6; i++)
	{
		ASSERT_TRUE(explorer[i]);
	}
	ASSERT_FALSE(explorer[6]);
	ASSERT_FALSE(explorer[7]);
}

TEST (MapExplorer, Init1)
{
	StageMap map;

	//	+--+--+--+--+
	//	| 0| 1| 2| 3|
	//	+--+--+--+--+  +--+
	//	| 4|  | 5| 6|  | 7|
	//	+--+  +--+--+  +--+

	map.Append(MapBrick(0,vector3di( 0,0,4),0,false,true,-1, 1, 4,-1));
	map.Append(MapBrick(0,vector3di( 2,0,4),0,false,true,-1, 2,-1, 0));
	map.Append(MapBrick(0,vector3di( 4,0,4),0,false,true,-1, 3, 5, 1));
	map.Append(MapBrick(0,vector3di( 6,0,4),0,false,true,-1,-1, 6, 2));
	map.Append(MapBrick(0,vector3di( 0,0,2),0,false,true, 0,-1,-1,-1));
	map.Append(MapBrick(0,vector3di( 4,0,2),0,false,true, 2, 6,-1,-1));
	map.Append(MapBrick(0,vector3di( 6,0,2),0,false,true,-1,-1, 5, 3));
	map.Append(MapBrick(0,vector3di(10,0,2),0,false,true,-1,-1,-1,-1));

	dynamic_bitset explorer(map.Size());
	PathFinder finder;
	finder.Explore(map, 0, 1, explorer);

	ASSERT_TRUE(explorer[0]);
	ASSERT_TRUE(explorer[4]);
	ASSERT_FALSE(explorer[1]);
	ASSERT_FALSE(explorer[2]);
	ASSERT_FALSE(explorer[3]);
	ASSERT_FALSE(explorer[5]);
	ASSERT_FALSE(explorer[6]);
	ASSERT_FALSE(explorer[7]);
}

TEST (MapExplorer, Init2)
{
	StageMap map;

	//	+--+--+--+--+
	//	| 0| 1| 2| 3|
	//	+--+--+--+--+  +--+
	//	| 4|  | 5| 6|  | 7|
	//	+--+  +--+--+  +--+
	map.Append(MapBrick(0,vector3di( 0,0,4),0,false,true,-1, 1, 4,-1));
	map.Append(MapBrick(0,vector3di( 2,0,4),0,false,true,-1, 2,-1, 0));
	map.Append(MapBrick(0,vector3di( 4,0,4),0,false,true,-1, 3, 5, 1));
	map.Append(MapBrick(0,vector3di( 6,0,4),0,false,true,-1,-1, 6, 2));
	map.Append(MapBrick(0,vector3di( 0,0,2),0,false,true, 0,-1,-1,-1));
	map.Append(MapBrick(0,vector3di( 4,0,2),0,false,true, 2, 6,-1,-1));
	map.Append(MapBrick(0,vector3di( 6,0,2),0,false,true,-1,-1, 5, 3));
	map.Append(MapBrick(0,vector3di(10,0,2),0,false,true,-1,-1,-1,-1));

	dynamic_bitset explorer(map.Size());
	PathFinder finder;
	finder.Explore(map, 6, 2, explorer);

	ASSERT_TRUE(explorer[3]);
	ASSERT_TRUE(explorer[5]);
	ASSERT_TRUE(explorer[6]);
	ASSERT_FALSE(explorer[0]);
	ASSERT_FALSE(explorer[1]);
	ASSERT_FALSE(explorer[2]);
	ASSERT_FALSE(explorer[4]);
	ASSERT_FALSE(explorer[7]);

	explorer.resize(map.Size());
	explorer.reset();
	finder.Explore(map, 0, 6, explorer);

	for (int i=0; i<6; i++)
	{
		ASSERT_TRUE(explorer[i]);
	}
	ASSERT_FALSE(explorer[6]);
	ASSERT_FALSE(explorer[7]);
}